/*
 * Created on 10.08.2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.opencube.oms;

import java.util.HashMap;

/**
 * Key-Tec Landsberg
 * 
 * @author at 10.08.2004 15:51:25
 */
public class OMSDataFactory
{
    private static HashMap m_omsConnections = new HashMap();
    private static int m_userId=0;
    private static String configFolder="application_resources";
    private static String lockKey;
    private static String m_configFolderPath="";
    public static void setConfigFolderPath(String configFolderPath) { 
    	m_configFolderPath = configFolderPath;
    }
    public static OMSData getOMSData(String connectionId){
    	return getOMSData(connectionId,getConfigFolder());
    }
    public static String getLockKey() {
    	return lockKey;
    }
    public static OMSData getOMSData(String connectionId, String configFolder)
    {
        try
        {
        	setConfigFolder(configFolder);
        	String key = connectionId+"-"+getConfigFolder();
            if (m_omsConnections.containsKey(key))
            {
            	OMSData omsData = (OMSData) m_omsConnections.get(key);
            	omsData.setUserId(m_userId);
                return omsData;
            }
            else
            {
                //Erstelle OMSData
                OMSData omsData = null;
                String compPath=m_configFolderPath;
                String fullpath ="";
                    omsData = new OMSData(compPath+getConfigFolder(), connectionId,m_userId);
                
                omsData.getDataSource().setAutoCommit(true);
                
                lockKey = omsData.getLockKey();
                m_omsConnections.put(key, omsData);
           // org.opencube.util.services.logging.Logger.init( "logs/log.txt","DEBUG" );

                return omsData;
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
    
    public static void setUserId(int userId) { 
    	m_userId = userId;
    }
    
	/**
	 * @return Returns the configFolder.
	 */
	public static String getConfigFolder() {
		return OMSDataFactory.configFolder;
	}
	/**
	 * @param configFolder The configFolder to set.
	 */
	public static void setConfigFolder(String configFolder) {
		OMSDataFactory.configFolder = configFolder;
	}
}